package org.example.code.nine_mouth;

import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String s = in.nextLine();
            if(s.isEmpty()){
                break;
            }
            int sum = fun(s);
            if(sum==-1){
                System.out.println("valid");
            }else{
                System.out.println("invalid "+sum);
            }
        }
    }

    private static int fun(String s) {
        int len = s.length();
        if(len<2){
            return len;
        }
        if(s.charAt(0)!='['){
            return 0;
        }
        Stack<Character> stack = new Stack<>();
        int sum = 0;
        boolean flag = false;
        for(int i=0;i<len;i++){
            char c = s.charAt(i);
            if(c=='['){
                if(stack.isEmpty()){
                    stack.push(c);
                }else if(stack.peek()=='['){
                    stack.push(c);
                }
                else{
                    return sum;
                }
            }
            else if((c>='a'&&c<='z')||(c>='0'&&c<='9')){
                stack.push(c);
            }
            else if(c==','){
                if(stack.peek()=='['){
                    if(flag){
                        continue;
                    }
                    return sum;
                }
                while(!stack.isEmpty()&&stack.peek()!='['){
                    if(stack.peek()==','){
                        return sum;
                    }
                    stack.pop();
                }
            }
            else if(c==']'){
                if(!stack.isEmpty()){
                    if(stack.peek()=='[') {
                        stack.pop();
                        continue;
                    }
                    while(stack.peek()!='['){
                        stack.pop();
                    }
                    if(i!=len-1){
                        flag=true;
                    }
                    stack.pop();
                }
            }
            sum++;
        }
        if(stack.isEmpty()){
            return -1;
        }
        return sum;
    }
}